#!/usr/bin/env python3

def print_matrix(matrix):
	print('='* 10, len(matrix))
	for l in matrix:
		print(l)
	print('*' * 40)

def filt_img(img, filt):
	dst_dim = len(img) - len(filt) + 1
	filt_dim = len(filt)
	res = []
	for r in range(dst_dim):
		res.append([])
		for c in range(dst_dim):
			t = 0
			for i in range(filt_dim):
				for j in range(filt_dim):
					t = t + img[r+i][c+j] * filt[i][j]
			res[-1].append(t)
	return res

def transpose(matrix):
	dim = len(matrix)
	m = [[0]* dim] * dim
	for i in range(dim):
		for j in range(dim):
			m[i][j] = matrix[j][i]
	return m

#line = [0, 0, 0, 1, 1, 1] *5 
#img_vert = [line] * 30

line = [0, 0, 1, 1] * 10 
img_vert = [line] * 40
print_matrix(img_vert)

img_hori = transpose(img_vert)
print_matrix(img_hori)

filt = [[-1, 0, 1], [-1, 0, 1], [-1, 0, 1]]
print_matrix(filt)

res_vert = filt_img(img_vert, filt)
print_matrix(res_vert)

res_hori = filt_img(img_hori, filt)
print_matrix(res_hori)
